package com.yanyu.space.common.db.config;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.p6spy.engine.spy.appender.MessageFormattingStrategy;

import java.time.LocalDateTime;

/**
 * @author yanyu
 * 引入spy.properties logMessageFormat
 */
public class P6spySqlFormatConfig implements MessageFormattingStrategy {
    @Override
    public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql, String url) {
        return StringUtils.isNotBlank(sql) ? LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss")
                + " | 耗时 " + elapsed + "ms | SQL语句：" + "\n" + sql.replaceAll("[\\s]+", " ") + "," : " ";
    }
}
